python map and filter

26

>>> doubled_odds = map(lambda n: n * 2, filter(lambda n: n % 2 == 1, numbers))
>>> doubled_odds = [n * 2 for n in numbers if n % 2 == 1]
#Using map() and filter() functions add 2000 to the values below 8000.
lst1=[1000, 500, 600, 700, 5000, 90000, 17500]

lst2= list(map(lambda x: x+2000, filter(lambda x: x<8000, lst1)))
print(lst2)

#output = [3000, 2500, 2600, 2700, 7000]
lst2 = list(map(lambda x: x+2000, filter(lambda x: x<8000, lst1)))

Comments

Submit
0 Comments